package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IOperatingDataFragmentModel;
import com.wgts.wgts.mvp.presenter.IOperatingDataFragmentPresenter;
import com.wgts.wgts.mvp.view.IOperatingDataFragmentView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.req.OperatingDataReq;
import com.wgts.wgts.netmodle.resp.OperatingDataEntity;

public class OperatingDataFragmentPresenter implements IOperatingDataFragmentPresenter {

    private IOperatingDataFragmentModel model;

    private IOperatingDataFragmentView view;

    private int indexPage = 1;

    private String day;

    private String orderTradeStatus;

    public OperatingDataFragmentPresenter(IOperatingDataFragmentModel model, IOperatingDataFragmentView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void initOperatingDate(String day, String orderTradeStatus) {
        OperatingDataReq req = new OperatingDataReq();
        indexPage = 1;
        req.day = day;
        req.orderTradeStatus = orderTradeStatus;
        req.pageIndex = String.valueOf(indexPage);
        this.day = day;
        this.orderTradeStatus = orderTradeStatus;
        model.operatingDate(req, new HttpResultSubscriber<OperatingDataEntity>() {
            @Override
            public void onSuccess(OperatingDataEntity operatingDataEntity) {
               if(operatingDataEntity.list.size() < Integer.valueOf(operatingDataEntity.pageSize)){
                   view.initOperatingDateResult(true, operatingDataEntity);
               }else{
                   view.initOperatingDateResult(false, operatingDataEntity);
                   indexPage++;
               }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void moreOpertingDate() {
        OperatingDataReq req = new OperatingDataReq();
        req.day = day;
        req.orderTradeStatus = orderTradeStatus;
        req.pageIndex = String.valueOf(indexPage);

        model.operatingDate(req, new HttpResultSubscriber<OperatingDataEntity>() {
            @Override
            public void onSuccess(OperatingDataEntity operatingDataEntity) {
                if(operatingDataEntity.list.size() < Integer.valueOf(operatingDataEntity.pageSize)){
                    view.moreOperatingDateResult(true, operatingDataEntity);
                }else{
                    view.moreOperatingDateResult(false, operatingDataEntity);
                    indexPage++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

}
